import { routerRedux } from 'dva/router';
import { setUser, deleteUser } from "@/utils/storage"
import { POST, FormPOST, GET, api } from '@/utils/request';
export default {
    namespace: 'login',

    state: {


    },

    effects: {
        *login({ payload }, { call, put, select }) {
            const { code, result } = yield call(FormPOST, api.login.login, payload);
            //登陆成功
            if (code === 0) {
                setUser(payload)    //设置登陆状态
                window.location.href = "./#/shares/shrinkHalfYear";
            }
        },
        *logout(_, { call, put }) {
            const { code, result } = yield call(POST, api.login.logout,);
            if(code === 0) {
                deleteUser();      //移除登陆状态
                yield put(              //跳转到登陆页面
                    routerRedux.push({
                        pathname: '/user/login'
                    })
                );
            }
        },
    },

    reducers: {

    },
};
